package com.yuelao.proxy.jdkproxy;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Proxy;

/**
 * @author FLY
 * @version v1.0
 * @project yuelao-server
 * @date 2017/9/26 14:30
 * @修改记录 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 */
@Slf4j
public class ProxyFactory {
    private Object target;

    public ProxyFactory(Object obj) {
        this.target = obj;
    }

    //给目标对象生成代理对象
    public Object getProxyInstance() {
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    //执行目标对象方法
                    log.info(("excuting proxy {}"), target.getClass());
                    Object returnValue = method.invoke(target, args);
                    return returnValue;
                }
        );
    }
}
